﻿@{
    ViewBag.Title = "登录";
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>登录</title>

    <link href="~/Content/bootstrap.min.css" rel="stylesheet">
    <link href="~/Content/font-awesome/css/font-awesome.css" rel="stylesheet">

    <link href="~/Content/animate.css" rel="stylesheet">
    <link href="~/Content/style.css" rel="stylesheet">
</head>
<body class="gray-bg">

    <div class="middle-box text-center loginscreen animated fadeInDown">
        <div>
            <h3>Welcome man!</h3>
            
            <form class="m-t" role="form">
                <div class="form-group">
                    <input type="text" id="userName" class="form-control" placeholder="请输入用户名" required="">
                </div>
                <div class="form-group">
                    <input type="password" id="password" class="form-control" placeholder="请输入密码" required="">
                </div>
                <button type="button" id="btnLogin" onclick="login();" class="btn btn-primary block full-width m-b">登录</button>

                <a href="#"><small>忘记密码?</small></a>
                <p class="text-muted text-center"><small>还没有账号?</small></p>
                <a class="btn btn-sm btn-white btn-block" href="/admin/account/register">注册</a>
            </form>
            <p class="m-t"> <small>仰望星空,脚踏实地.帮助他人,成就自我. © 2015</small> </p>
        </div>
    </div>

    <!-- Mainly scripts -->
    <script src="~/Scripts/jquery-2.1.1.js"></script>
    <script src="~/Scripts/bootstrap.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function() {
            $("#userName").focus();
        });

        function login() {
            var userName = $("#userName").val();
            if (userName == "") {
                $("#userName").focus();
                return false;
            }
            var password = $("#password").val();
            if (password == "") {
                $("#password").focus();
                return false;
            }
            var data = {
                UserName: userName,
                Password: password
            };
            var url = "/admin/api/account/logon";

            $.ajax({
                type: "post",
                url: url,
                data: data,
                dataType: "json",
                success: function (result) {
                    if (!result.iserror) {
                        window.location = "/admin";
                        return false;
                    }
                    console && console.log(result);
                    alert(result.message);
                    return false;
                }
            });
            return false;
        }
    </script>
</body>

</html>
